<div class="wrapMain" style="padding:10px">
<div class="row">
<table class="table table-bordered" style="background-color:#fff">
<thead>
<tr>
<td>Anime</td>
    <td>URL</td>
     <td>Result</td>
</tr> 
</thead>
<tbody>   
    <?php
	
		echo "<tr>";
		echo "<Td>".$data['name']."</td>";
		echo "<Td>";
			echo $data['url'];
		echo "</td>";
		echo "<td class='anime_id".$data['id']."'></td>";
		echo "</tr>";

	?>

    <tr><td colspan="3" align="center">
    <div class="loading_spinner" style="display:none; text-align:center"><img src="public/images/loading11.gif" /> Đăng Xử Lý Dữ Liệu ......</div>
    <a href="" class="btn btn-primary" id="submit_scan">Start Scan</a></td> </tr>
    </tbody>
</table>


<table class="table table-bordered " id="result" style="background-color:#fff">
<tbody>  
<tr>
	<td>Url</td>
    <td>STT</td>
    <td>Name</td>
    <td>Status</td>
     <td>Error</td>
</tr> 

 
   
 </tbody>
</table>

</div> <!-- End row -->
</div> <!-- End container -->
<script type="text/javascript">
	$(document).ready(function(){
	    /*
	     * Submit event
	     */

		 $('#submit_scan').click(function(e){
			 	e.preventDefault();
				$('.loading_spinner').css("display",'block');
				setTimeout( function(){
     //start function in settimeout

				//Ajax request
						$.ajax({
				// &manual=1 : Lấy những truyện chưa submit lần nào
				url: "<?php echo HOME;?>index.php?module=manage&act=manga&opt=scan_ajax&getanime2=1",
				type : 'POST',
				cache : false,
				async: false,
				data :{submitScan: 1},
				success : function(data){
				//	console.log(allTruyen);
					if(data){
						data = $.parseJSON(data);
						
							if(data.urls){
								$.each(data.urls, function(e,url){
									url.manga=data.id;
									url.alias=data.alias;
									url.manga_name=data.name;
									
									
									re=	pl_link(url);
									re= $.parseJSON(re);
								
								$('#result tr:last').after('<tr><td>'+url.link+'</td><td>'+url.thutu+'</td><td>'+url.name+'</td><td>'+re.status+'</td><td>'+re.error+'</td></tr>');		//Gui ajax request len de get link tung playlist
								}) //End of each truyen.pl
							//Send ajax request update lai
							}// End of if( truyen.pl)
							//Xong mot truyen
							
							//---------------------- Update truyen here ----------
								
								var data4={									
									   id:data.id
										}
								$.ajax({
										url : "<?php echo HOME;?>index.php?module=manage&act=manga&opt=scan_ajax&update_anime_scan2",
											type : 'POST',
											cache: false,
											async: false,
											data: data4,
										success : function(dt){} //end success
									});
							
							//Co the update trong day
						
						/*
						Nếu có truyện trả về thì bắt đầu lặp truyện, get link từng truyện và nội dung tương ứng
				*/
		

					}

				},

				complete: function(){
					$('.loading_spinner').css("display",'none');
					$('.loading_spinner').html('Scan Complete ...');
				//	$('.formLoading').hide();
		    	//	$('#wrapLoadMoreItems').hide();
		    	//	$('.userPostForm').css('opacity', '1');
				}

			});

				//End of ajax request

				}, 3000); // End of set timeout function 3 seconds 

		 }) // End of sumit scan click

		 

		 

		 //function send link playlist và return vè là array link, sau do get tung link 1, update database

			function pl_link(data){
			var dt;
	   		$.ajax({
	    		url : "<?php echo HOME;?>index.php?module=manage&act=manga&opt=scan_ajax&submit_chap2",
	    		type : 'POST',
	    		cache: false,
	    		async: false,
	    		data: data,
	    		success : function(data2){	
				dt= data2;
		    	} //end success
	    	});
			return dt;
	   	}

		//end of sendl ink playlist
	

		 


	});

</script>

